<template>
  <!-- 采集模板设定 -->
  <div class="app-container">
    <el-row :gutter="10" class="button-wrap">
      <el-col :span="1.5">
        <el-button v-clickForbidden icon="el-icon-document-checked" size="mini" @click="handleSave">保存</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <!-- 表格展示start -->
        <el-table
          ref="multipleTable"
          v-loading="tableLoading"
          stripe
          class="table-list"
          :data="tableData"
          :row-style="rowClass"
          row-key="id"
          :default-expand-all="true"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @selection-change="handleSelectionChange"
        >
          <el-table-column :selectable="checkSelectable" type="selection" width="55" align="center" />
          <el-table-column prop="fieldName" label="字段名称" min-width="180" header-align="center" align="left" />
          <el-table-column prop="orderNum" label="排序" min-width="120" align="center" />
          <el-table-column prop="isRequired" label="必填" min-width="120" align="center">
            <template slot-scope="{row}">
              <span v-if="row.isRequired === '0'">是</span>
              <span v-if="row.isRequired === '1'">否</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" min-width="120" align="center">
            <template slot-scope="{row}">
              <span v-if="row.status === '0'">是</span>
              <span v-if="row.status === '1'">否</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" width="180" align="center" />
        </el-table>
        <!-- 表格展示end-->
      </el-col>
    </el-row>
    <!-- 字段新增弹框 -->
    <addDialog ref="addDialog" />
    <!-- 字段详情弹框 -->
    <detailDialog ref="detailDialog" />
  </div>
</template>

<script>
// import { listSupperType, removeSupperType } from '@/api/superviseBaseInfo/typeManage/organizationType'
import addDialog from './components/addDialog'
import detailDialog from './components/detailDialog'
import { mapState } from 'vuex'
export default {
  name: 'PersonneType',
  components: {
    detailDialog,
    addDialog
  },
  data() {
    return {
      tableLoading: false, // 表格加载
      highLevelSet: false, // 高级搜索
      // 筛选条件
      filters: {
        pageNum: 1,
        pageSize: 20,
        fieldName: ''
      },
      /* 列表 start */
      // 分页总条数
      total: 0,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 选中表格对话框的存储的值
      multipleSelection: [],
      // 高亮样式
      selectRow: [],
      // 表格数据
      tableData: [
        {
          id: '1',
          fieldName: '描述深度(m)',
          fieldVal: 'depth',
          orderNum: 1,
          isRequired: '0',
          status: '1',
          isExrernal: '1',
          createTime: '2021-05-05',
          children: [
            {
              id: '1001',
              fieldName: '由',
              fieldVal: 'startDepth',
              orderNum: 1,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              children: [],
              createTime: '2021-05-05'
            },
            {
              id: '1002',
              fieldName: '至',
              fieldVal: 'endDepth',
              orderNum: 2,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              children: [],
              createTime: '2021-05-05'
            }
          ]
        },
        {
          id: '2',
          fieldName: '地层描述',
          fieldVal: 'depth',
          orderNum: 2,
          isRequired: '0',
          status: '1',
          isExrernal: '1',
          createTime: '2021-05-05',
          children: [
            {
              id: '2001',
              fieldName: '土的名称',
              fieldVal: 'soilName',
              orderNum: 1,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              createTime: '2021-05-05',
              children: []
            },
            {
              id: '2002',
              fieldName: '颜色',
              fieldVal: 'soilColor',
              orderNum: 2,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              createTime: '2021-05-05',
              children: []
            },
            {
              id: '2003',
              fieldName: '其他性质',
              fieldVal: 'ohterProperties',
              orderNum: 3,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              createTime: '2021-05-05',
              children: []
            },
            {
              id: '2004',
              fieldName: '光泽反应',
              fieldVal: 'glossReaction',
              orderNum: 4,
              isRequired: '0',
              status: '1',
              isExrernal: '1',
              children: [],
              createTime: '2021-05-05'
            }
          ]
        },
        {
          id: '3',
          fieldName: '密度',
          fieldVal: 'depth',
          orderNum: 3,
          isRequired: '0',
          status: '1',
          isExrernal: '1',
          createTime: '2021-05-05',
          children: []
        }
      ]
      /* 列表 end */
    }
  },
  computed: {
    ...mapState({
      needTagsView: (state) => state.settings.tagsView
    }),
    // 高级搜索显示隐藏
    handleTagShow() {
      return this.highLevelSet
    }
  },
  mounted() {
    // 获取列表数据
    this.getList()
  },
  methods: {
    // 获取列表数据
    async getList() {
      this.tableLoading = true
      // const res = await listSupperType(this.filters)
      // console.log(res)
      this.tableLoading = false
      // this.addTaleData()
    },
    // list表单补空白行
    addTaleData() {
      if (this.tableData.length < this.filters.pageSize) {
        var arr = {}
        this.tableData.push(arr)
        this.addTaleData()
      }
    },
    /* 表单行选中事件 start */
    // 高亮样式
    rowClass({ row, rowIndex }) {
      if (this.selectRow.includes(rowIndex)) {
        return { 'background-color': 'rgba(185,221,249,.75)' }
      }
    },
    // 点击表格前面选框时触发的事件
    handleSelectionChange(selection) {
      // if (selection.length === 0) {
      //   this.tableData.forEach(item => {
      //     item.status = '0'
      //   })
      //   console.log(this.tableData)
      // }
      // selection.forEach(item => {
      //   item.status = '1'
      // })
      this.multipleSelection = selection
    },
    checkSelectable(row) {
      // 仅最低级可以勾选
      return !row.children.length > 0
    },
    /* 表单行选中事件 end */

    /* 按钮 start */
    handleSave() {
      this.msgSuccess('保存成功')
    }
    /* 按钮 end */
  }
}
</script>

